/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     ListNode *next;
 *     ListNode() : val(0), next(nullptr) {}
 *     ListNode(int x) : val(x), next(nullptr) {}
 *     ListNode(int x, ListNode *next) : val(x), next(next) {}
 * };
 */
class Solution {
public:
    typedef struct ListNode* Node;
    ListNode* deleteDuplicates(ListNode* head) {
        Node virnode=new ListNode(-1);
        virnode->next=head;
        Node cur=virnode;
        while(cur->next && cur->next->next)
        {
            if(cur->next->val==cur->next->next->val)
            {
                int x=cur->next->val;
                while(cur->next && cur->next->val==x)
                {
                    cur->next=cur->next->next;
                }
            }
            else cur=cur->next;
        }
        return virnode->next;
    }
};
